home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / include / libbonobo-2.0 / bonobo / bonobo-macros.h < prev    next >
Encoding:
C/C++ Source or Header  |  2006-01-09  |  3.5 KB  |  101 lines

  1. /**
  2.  * Useful macros.
  3.  *
  4.  * Author:
  5.  *   Darin Adler <darin@bentspoon.com>
  6.  *
  7.  * Copyright 2001 Ben Tea Spoons, Inc.
  8.  */
  9. #ifndef _BONOBO_MACROS_H_
  10. #define _BONOBO_MACROS_H_
  11.  
  12. #include <glib/gmacros.h>
  13.  
  14. G_BEGIN_DECLS
  15.  
  16. /* Macros for defining classes.  Ideas taken from Nautilus and GOB. */
  17.  
  18. /* Define the boilerplate type stuff to reduce typos and code size.  Defines
  19.  * the get_type method and the parent_class static variable. */
  20.  
  21. #define BONOBO_BOILERPLATE(type, type_as_function, corba_type,        \
  22.                parent_type, parent_type_macro,        \
  23.                register_type_macro)                \
  24. static void type_as_function ## _class_init    (type ## Class *klass);    \
  25. static void type_as_function ## _instance_init (type          *object);    \
  26. static parent_type ## Class *parent_class = NULL;            \
  27. static void                                \
  28. type_as_function ## _class_init_trampoline (gpointer klass,        \
  29.                         gpointer data)        \
  30. {                                    \
  31.     parent_class = (parent_type ## Class *)g_type_class_ref (    \
  32.         parent_type_macro);                    \
  33.     type_as_function ## _class_init ((type ## Class *)klass);    \
  34. }                                    \
  35. GType                                    \
  36. type_as_function ## _get_type (void)                    \
  37. {                                    \
  38.     static GType object_type = 0;                    \
  39.     if (object_type == 0) {                        \
  40.         static const GTypeInfo object_info = {            \
  41.             sizeof (type ## Class),                \
  42.             NULL,        /* base_init */            \
  43.             NULL,        /* base_finalize */        \
  44.             type_as_function ## _class_init_trampoline,        \
  45.             NULL,        /* class_finalize */        \
  46.             NULL,               /* class_data */        \
  47.             sizeof (type),                    \
  48.             0,                  /* n_preallocs */        \
  49.             (GInstanceInitFunc) type_as_function ## _instance_init \
  50.         };                            \
  51.         object_type = register_type_macro            \
  52.             (type, type_as_function, corba_type,        \
  53.              parent_type, parent_type_macro);        \
  54.     }                                \
  55.     return object_type;                        \
  56. }
  57.  
  58. /* Just call the parent handler.  This assumes that there is a variable
  59.  * named parent_class that points to the (duh!) parent class.  Note that
  60.  * this macro is not to be used with things that return something, use
  61.  * the _WITH_DEFAULT version for that */
  62. #define BONOBO_CALL_PARENT(parent_class_cast, name, args)        \
  63.     ((parent_class_cast(parent_class)->name != NULL) ?        \
  64.      parent_class_cast(parent_class)->name args : (void)0)
  65.  
  66. /* Same as above, but in case there is no implementation, it evaluates
  67.  * to def_return */
  68. #define BONOBO_CALL_PARENT_WITH_DEFAULT(parent_class_cast,        \
  69.                     name, args, def_return)        \
  70.     ((parent_class_cast(parent_class)->name != NULL) ?        \
  71.      parent_class_cast(parent_class)->name args : def_return)
  72.  
  73.  
  74. #define BONOBO_CLASS_BOILERPLATE(type, type_as_function,        \
  75.                  parent_type, parent_type_macro)    \
  76.     BONOBO_BOILERPLATE(type, type_as_function, type,        \
  77.                parent_type, parent_type_macro,        \
  78.                BONOBO_REGISTER_TYPE)
  79. #define BONOBO_REGISTER_TYPE(type, type_as_function, corba_type,    \
  80.                  parent_type, parent_type_macro)        \
  81.     bonobo_type_unique (parent_type_macro, NULL, NULL, 0,        \
  82.                 &object_info, #type)
  83.  
  84. #define BONOBO_CLASS_BOILERPLATE_FULL(type, type_as_function,        \
  85.                       corba_type,            \
  86.                       parent_type, parent_type_macro)    \
  87.     BONOBO_BOILERPLATE(type, type_as_function, corba_type,        \
  88.                parent_type, parent_type_macro,        \
  89.                BONOBO_REGISTER_TYPE_FULL)
  90. #define BONOBO_REGISTER_TYPE_FULL(type, type_as_function, corba_type,    \
  91.                   parent_type, parent_type_macro)    \
  92.     bonobo_type_unique (parent_type_macro,                \
  93.                 POA_##corba_type##__init,            \
  94.                 POA_##corba_type##__fini,            \
  95.                 G_STRUCT_OFFSET (type##Class, epv),        \
  96.                 &object_info, #type)
  97.  
  98. G_END_DECLS
  99.  
  100. #endif /* _BONOBO_MACROS_H_ */
  101.